package com.chat.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;

public class FileUtils {

    /**
     * 保存文件
     * @param content
     * @param path
     * @param fileName
     */
    public static void saveFile(byte[] content,String path,String fileName){
        File file = new File(path+"/"+fileName);
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            fileOutputStream.write(content);
            fileOutputStream.flush();
            fileOutputStream.close();
        }
        catch(IOException e){
            e.printStackTrace();
        }
    }

    /**
     * 下载文件
     * @param path
     * @param fileName
     * @return 返回文件内容
     */
    public static byte[] downFile(String path,String fileName){
        try {
            File file = new File(path + "/" + fileName);
            FileInputStream fileInputStream = new FileInputStream(file);
            byte[] content = fileInputStream.readAllBytes();
            return content;
        }
        catch(IOException e){
            e.printStackTrace();
        }
        return null;
    }

}
